pwd |
Prints the current working directory. |
pwd |
cd <directory> |
Changes the current directory to <directory>. |
cd /var/log (go to /var/log directory) |
ls [-l] [-a] [-h] |
Lists directory contents. -l for detailed list, -a for hidden files, -h for human-readable file sizes.
|
ls -lah |
mkdir <dir> |
Creates a new directory named <dir>. |
mkdir my_folder |
rmdir <dir> |
Removes an empty directory named <dir>. |
rmdir my_folder |
rm <file/dir> |
Removes files or directories. Use caution; directories require -r (recursive). |
rm -r old_folder |
cp <src> <dest> |
Copies files or directories from <src> to <dest>. Use -r for directories. |
cp file.txt /tmp |
mv <src> <dest> |
Moves or renames files/directories. |
mv file.txt new_file.txt |
cat <file> |
Concatenates files to standard output. Often used just to view file contents. |
cat /etc/hosts |
less <file> |
Opens a file for paged viewing. Navigate with arrow keys, space, and q to quit. |
less /var/log/syslog |
head <file> |
Displays the first 10 lines of a file by default. Use -n to specify number of lines. |
head -n 20 example.log |
tail <file> |
Displays the last 10 lines of a file by default. Commonly used with -f for logs. |
tail -f /var/log/syslog |
chmod <mode> <file> |
Changes file or directory permissions. Modes can be numeric (e.g., 755) or symbolic. |
chmod 755 script.sh |
chown <user>:<group> |
Changes file or directory ownership to the specified user and group. |
chown ubuntu:ubuntu /var/www/html |
find <path> ... |
Searches for files in a directory hierarchy. Very powerful with many options |
find /home -name "file.txt" |
grep <pattern> |
Searches text or files for matching patterns. Supports regular expressions. |
grep "error" /var/log/syslog |
sort <file> |
Sorts lines of text in specified files. Use -r for reverse, -n for numeric sort. |
sort -r names.txt |
wc [-l] [-w] [-c] |
Counts lines (-l), words (-w), or bytes/characters (-c). |
wc -l file.txt |
ps aux |
Lists running processes with user, CPU, memory usage, etc. |
ps aux |
top / htop |
Displays real-time processes/activity. htop is a more user-friendly version if installed.
|
top (or) htop
|
kill <PID> |
Sends a signal to a process (default is SIGTERM). |
kill 1234 |
killall <name> |
Kills processes by name rather than PID. |
killall chrome |
df -h |
Shows disk usage of mounted file systems in human-readable format. |
df -h |
du -sh <dir> |
Summarizes disk usage of a given directory (or file). -s for summary, -h for human. |
du -sh /var |
free -h |
Displays current memory usage in human-readable format. |
free -h |
history |
Lists previously executed commands. Can use !<number> to re-run. |
history |
env |
Displays current environment variables. |
env |
export <VAR>=<val> |
Sets (and exports) environment variables for the current shell/session. |
export PATH="/usr/local/bin:$PATH" |
alias <name>=... |
Creates an alias for a command. Useful for shortcuts. |
alias ll='ls -la' |
uname -a |
Shows system information (kernel name, version, etc.). |
uname -a |
whoami |
Prints the effective username of the current user. |
whoami |
date |
Displays or sets the system date and time. |
date |
uptime |
Shows how long the system has been running, plus load averages. |
uptime |
ping <host> |
Checks network connectivity/reachability to a host. |
ping google.com |
netstat / ss |
Displays network connections, routing tables, etc. ss is the more modern tool. |
ss -tuln |
ip / ifconfig |
Shows or manipulates network interface settings. ip is newer than ifconfig. |
ip addr show |
tar -czvf <file> |
Creates (c), compresses (z), and writes (v=verbose) an archive. -f specifies file. |
tar -czvf archive.tar.gz /path/to/dir |
unzip / zip |
Extracts or creates zip archives. |
zip -r archive.zip folder_to_zip |
which <command> |
Shows the full path of a command. |
which python |
man <command> |
Displays the manual page for a command; essential for finding options and usage. |
man grep |
nano <file> |
Simple command-line text editor. Great for quick edits. |
nano /etc/nginx/nginx.conf |
vim <file> |
Powerful command-line text editor with modes. Takes time to learn, widely used. |
vim /etc/environment |
ssh user@hostname |
Securely connects to a remote host. |
ssh user@192.168.0.10 |
scp <src> <dest> |
Securely copies files between hosts over SSH. |
scp file.txt user@remote:/home |
wget <URL> |
Retrieves content from web servers. Handy for file downloads. |
wget http://example.com/file.tar.gz |
curl [options] <URL> |
Transfers data to/from servers. Versatile: can perform requests, test APIs, etc. |
curl -X GET http://api.example.com/data |
gcloud <command> ... |
CLI for managing GCP resources (VMs, storage, networking, etc.). |
gcloud compute instances list |